﻿using System;
using System.Collections.Generic;

public class XMLObjectRegisterForEditor
{
    private static readonly Dictionary<string, XMLParserInfo> m_xml_object_dict =
        new Dictionary<string, XMLParserInfo>();

    private static bool m_binit;
    private static readonly string cndPath = "";
    private static bool isHeatRenewal = false;

    public static void ResetInEditor()
    {
        m_binit = false;
    }

    public static string GetUpdateCDNABFolder()
    {
        return cndPath;
    }

    ///// <summary>
    ///// 开发目录，编辑器用,配置cdn资源目录，运行时不使用该目录
    ///// </summary>
    ///// <returns></returns>
    public static void RegistAllObject(bool heatRenewal = false, string CDNABFolderPath = null)
    {
        if (m_binit)
        {
            return;
        }

        RegisterXMLObject(typeof(DressListInfo), XmlPathDefines.Dress, new DressXMLParser());
        m_binit = true;
    }

    public static void RegisterXMLObject(Type t, string xmlpath, XMLParserBase xmlParser)
    {
        if (m_xml_object_dict.ContainsKey(xmlpath) == false)
        {
            var parserinfo = new XMLParserInfo(t, xmlpath, xmlParser);
            m_xml_object_dict.Add(xmlpath, parserinfo);
        }

        XMLObjectRegister.RegisterXMLObject(t, xmlpath);
    }

    private static void RegisterXMLObjectParser(Type t, string xmlpath, XMLParserBase xmlParser)
    {
        if (m_xml_object_dict.ContainsKey(xmlpath) == false)
        {
            var parserinfo = new XMLParserInfo(t, xmlpath, xmlParser);
            m_xml_object_dict.Add(xmlpath, parserinfo);
        }

        XMLObjectRegister.RegisterXMLObjectParser(t, xmlpath);
    }

    public static XMLParserInfo FindParser(string path)
    {
        if (m_xml_object_dict.ContainsKey(path) == false)
        {
            return null;
        }

        return m_xml_object_dict[path];
    }

    public static HashSet<string> GetAllParserPath()
    {
        var paths = new HashSet<string>();

        foreach (var pair in m_xml_object_dict)
        {
            if (!paths.Contains(pair.Key))
            {
                paths.Add(pair.Key);
            }
        }

        return paths;
    }
}